<template>
  <div class="tableListBox">
    <div class="common-header">
      <div style="cursor: pointer" @click="back">
        <i class="vxe-icon-arrow-left" style="vertical-align: middle"></i
        ><span style="vertical-align: middle">返回</span>
      </div>
    </div>
    <div class="anthorContent">
      <el-scrollbar style="height: 100%">
        <p class="title"><span class="titleName">基础信息</span></p>
        <FormCommon v-model="form" />
        <p class="title"><span class="titleName">项目履历</span></p>
        <TableCommon ref="common" :columns="tableColumn" :tableData="tableData" :total="total" @pager="pager" />
      </el-scrollbar>
    </div>
  </div>
</template>
<script>
import FormCommon from './formCommon.vue';
import TableCommon from './tableCommon.vue';
export default {
  components: { FormCommon, TableCommon },
  data() {
    return {
      params: {
        page: 1,
        size: 10,
      },
      form: {
        employeeCode: '',
        employeeName: '',
        gender: '',
        age: '',
        phoneNumber: '',
        birthdate: '',
        origin: '',
        politicsStatus: '',
        natureEmployment: '',
        company: '',
        post: '',
        individualRank: '',
        category: '',
        idCard: '',
        license: '',
        awards: '',
      },
      tableColumn: [
        {
          field: 'belongOrganization',
          title: '所属组织',
          editRender: {},
          slots: {
            edit: 'belongOrganization',
          },
        },
        {
          field: 'belongProject',
          title: '所属项目',
          editRender: {},
          slots: {
            edit: 'belongProject',
          },
        },
        {
          field: 'job',
          title: '岗位',
          editRender: {},
          slots: {
            edit: 'job',
          },
        },
        {
          field: 'startTime',
          title: '调入时间',
          editRender: {},
          slots: {
            default: 'd_startTime',
          },
        },
        {
          field: 'endTime',
          title: '调出时间',
          editRender: {},
          slots: {
            default: 'd_endTime',
          },
        },
      ],
      tableData: [],
      total: 0,
    };
  },
  created() {
    this.getQuery();
    this.getInfo();
  },
  methods: {
    back() {
      jDiwork.closeWin();
      jDiwork.openService('1752188790968418304');
    },
    edit() {
      const { id, idCard } = this.form;
      this.$router.push({ path: '/staffList/detailEdit', query: { id, idCard } });
    },
    getQueryVariable(variable) {
      var query = window.location.search.substring(1);
      if (!query) {
        query = window.location.hash.split('?')[1];
      }
      if (!query) {
        return;
      }
      var vars = query.split('&');
      for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split('=');
        if (pair[0] == variable) {
          return decodeURIComponent(pair[1]);
        }
      }
      return '';
    },
    getQuery() {
      this.form.id = this.getQueryVariable('id');
      this.form.idCard = this.getQueryVariable('idCard');
    },
    pager({ currentPage, pageSize }) {
      this.params.page = currentPage;
      this.params.size = pageSize;
      this.getInfo();
    },
    getInfo() {
      const { page, size } = this.params;
      const { idCard } = this.form;
      this.$api.getEmployeeInfo({ idCard, page, size }).then((res) => {
        if (res.code === 0) {
          const { businessEmployeeMasterByIdCard, projectRecordDto } = res.data;
          if (businessEmployeeMasterByIdCard) {
            Object.keys(this.form).forEach((key) => {
              this.form[key] = businessEmployeeMasterByIdCard[key] || this.form[key];
            });
          }
          if (projectRecordDto) {
            this.tableData = projectRecordDto.list;
            this.total = projectRecordDto.total;
          }
        }
        console.log();
      });
    },
    exp() {
      this.$refs.common.exp();
    },
  },
};
</script>
